package com.itheima.service.impl;

import com.itheima.mapper.LoginMapper;
import com.itheima.pojo.KsClass;
import com.itheima.pojo.LoginDto;
import com.itheima.pojo.User;
import com.itheima.service.LoginService;
import com.itheima.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
@Service
public class LoginServiceImpl implements LoginService {
    @Autowired
    private LoginMapper loginMapper;
    @Override
    public ResponseResult findPosition(String mobile) {
        User user = loginMapper.findUserById(mobile);
        if (user != null){
        if (user.getRoleId() == 1){
            List<KsClass> ksClassAll = loginMapper.findKsClassAll();
            return new ResponseResult<>(0,"操作成功",ksClassAll);
        }else if (user.getRoleId() == 2){
            return new ResponseResult<>(0,"操作成功","学生账号");
        }
        }
        return new ResponseResult<>(1,"操作失败",null);
    }

    @Override
    public User login(LoginDto loginDto) {
        String name = loginDto.getName();
        String password = loginDto.getPassword();
        User user = loginMapper.login(name, password);
        return user;
    }


}